package com.honry.common.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware{
	private static ApplicationContext applicationContext;
	
	/**
	 * 从Spring的applicationContext中获取实例
	 * @return
	 */
	public static ApplicationContextProvider instance(){
		return (ApplicationContextProvider)applicationContext.getBean("applicationContextProvider");
	}
	public ApplicationContextProvider() {
		super();
	}
	public ApplicationContext applicationContext(){
		return ApplicationContextProvider.applicationContext;
	}
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		if(ApplicationContextProvider.applicationContext==null){
			ApplicationContextProvider.applicationContext=applicationContext;
		}
	}

}
